package com.situ.company.project.service.impl;

import java.util.List;

import com.situ.company.project.dao.IProjectDao;
import com.situ.company.project.dao.impl.ProjectDaoImpl;
import com.situ.company.project.model.ProjectModel;
import com.situ.company.project.service.IProjectService;
import com.situ.company.score.dao.IScoreDao;
import com.situ.company.score.dao.impl.ScoreDaoImpl;
import com.situ.company.score.model.ScoreModel;
import com.situ.company.util.FmtEmpty;

public class ProjectServiceImpl implements IProjectService {
	IProjectDao dao=new ProjectDaoImpl();
	IScoreDao sdao=new ScoreDaoImpl();
	public String insert(ProjectModel model) {
		ProjectModel p0=new ProjectModel(model.getCode());
		ProjectModel p1=dao.selectModel(p0);
		if(p1==null) {
			Integer res = dao.insert(model);
			return res == null ? null : res.toString();
		}
		else {
			return "repeat";	
		}
	}

	public String delete(ProjectModel model) {
		ProjectModel m0=new ProjectModel(model.getCode());
		ProjectModel mdb = dao.selectModel(m0);
		if(FmtEmpty.isEmpty(mdb.getCodeEmp())) {
			return dao.delete(model)+"";
		}
		return "repeat";
	}

	public String update(ProjectModel model) {
		return dao.updateActive(model)+"";
	}

	public List<ProjectModel> selectList(ProjectModel model) {
		String code=model.getCode();
		model.setCode(code==null?"%%":"%"+code+"%");
		String name=model.getName();
		model.setName(name==null?"%%":"%"+name+"%");
		return dao.selectList(model);
	}

	public ProjectModel selectModel(ProjectModel model) {
		return dao.selectModel(model);
	}
	public Integer selectCount(ProjectModel model) {
		ProjectModel p0=new ProjectModel();
		return dao.selectCount(p0);
		
	}

	public String updateEmp(ProjectModel model) {
			ScoreModel s0=new ScoreModel();
			s0.setCodeEmp(model.getCodeEmp());
			s0.setCodePro(model.getCode());
			ScoreModel mdb = sdao.selectModel(s0);
			if(mdb==null)
			sdao.insert(s0);
			else sdao.update(s0);
			return dao.updateActive(model)+"";

	}
}
